package task1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StudentSearch {
    public static void searchById(List<Student> students, String id){
        Iterator iterator = students.iterator();
        while(iterator.hasNext()){
            Student student = (Student)iterator.next();
            if(student.getId().equals(id)){
                System.out.println("查询成功：" +student);
                return;
            }
        }
        System.out.println("查询失败");
    }

    public static void searchByName(List<Student> students, String name){
        List<Student> result = new ArrayList<>();
        for(Student student: students){
            if (student.getName().equals(name)) {
                result.add(student);
            }
        }
        if(0 == result.size()){
            System.out.println("查询失败");
        }else{
            System.out.println("查询成功：" + result);
        }
    }
}
